package xyz.xtt.admin.service.impl;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.yulichang.base.MPJBaseServiceImpl;
import org.apache.ibatis.executor.BatchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import xyz.xtt.admin.entity.TblActivityLog;
import xyz.xtt.admin.mapper.ActivityLogMapper;
import xyz.xtt.admin.service.IActivityLogService;

import java.util.List;
import java.util.Objects;

/**
 * @author Jim kwok
 * @since 2025/2/28
 */

@Service
public class ActivityLogServiceImpl extends MPJBaseServiceImpl<ActivityLogMapper, TblActivityLog> implements IActivityLogService {
    @Autowired
    ActivityLogMapper activityLogMapper;

    /**
     * 按照默认批次量【1000】入库
     */
    @Override
    @Transactional
    public List<BatchResult> batchSave(List<TblActivityLog> list) {
        Assert.isTrue(Objects.nonNull(list) && !list.isEmpty());
        return activityLogMapper.insert(list);
    }

    @Override
    public Integer updateOne(TblActivityLog obj) {
        Assert.notNull(obj);
        return activityLogMapper.updateById(obj);

    }

    @Override
    public TblActivityLog getOne(Long activityId,Long uid,String phone,Long assetId) {
        Assert.notNull(uid);
        Assert.notNull(assetId);
        QueryWrapper<TblActivityLog> query = new QueryWrapper<>();
        query.eq("activity_id",activityId);
        query.eq("user_id",uid);
        query.eq("user_phone",phone);
        query.eq("asset_id",assetId);

        return activityLogMapper.selectOne(query);
    }

    @Override
    public TblActivityLog getListById(Long id) {
        return activityLogMapper.selectById(id);
    }


}
